<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title></title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../../../lib/layui-v2.6.3/css/layui.css" media="all">
  <link rel="stylesheet" href="../../../css/public.css" media="all">
  <style>
      body {
          background-color: #ffffff;
      }
  </style>
</head>
<body>
<form class="layui-form" action="" lay-filter="demo-val-filter">
  <div class="layui-form layuimini-form" id="myForm">
    <div class="layui-form-item">
      <label class="layui-form-label ">名称</label>
      <div class="layui-input-block">
        <input type="text" name="name" class="layui-input" disabled="disabled">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label ">电话</label>
      <div class="layui-input-block">
        <input type="text" name="tel" class="layui-input" disabled="disabled">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label ">邮箱</label>
      <div class="layui-input-block">
        <input type="text" name="mail" class="layui-input" disabled="disabled">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label ">ip地址</label>
      <div class="layui-input-block">
        <input type="text" name="ip" class="layui-input" disabled="disabled">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label ">内容</label>
      <div class="layui-input-block">
        <textarea type="text" name="content" class="layui-textarea" disabled="disabled"></textarea>
      </div>
    </div>
    </div>
  </div>
</form>

<script src="../../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../../lib/jsencrypt/jsencrypt.js" charset="utf-8"></script>
<script src="../../../api/common.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        function getQueryString(name) {
            var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
            var r = window.location.search.substr(1).match(reg);
            if (r != null) {
                return decodeURIComponent(r[2]);
            }
            return null;
        }

        var id = getQueryString('id');

        $.ajax({
            type: 'GET',
            url: local + 'mailbox/get/' + id,
            dataType: "json",
            headers: {
                'Authorization': `Bearer ${ localStorage.getItem("token") }`,
            },
            contentType: 'application/json;charset=UTF-8',
            success: function (res) {
                console.log(res)
                form.val('demo-val-filter', {
                    "name":res.data.name,
                    "tel":res.data.tel,
                    "mail":res.data.mail,
                    "ip":res.data.ip,
                    "content":res.data.content

                });
                form.render('select')
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.alert('操作失败！！！' + XMLHttpRequest.status + "|" + XMLHttpRequest.readyState + "|" + textStatus, {icon: 5});
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var obj = data.field

            $.ajax({
                type: 'POST',
                url: local + 'role/insert',
                data: JSON.stringify(obj),
                dataType: "json",
                headers: {
                    'Authorization': `Bearer ${ localStorage.getItem("token") }`,
                },
                contentType: 'application/json;charset=UTF-8',
                success: function (res) {//res为相应体,function为回调函数
                    console.log('data', res)
                    if (res.code === 200) {
                        // layer.alert('添加成功');
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                        parent.layui.table.reload('currentTableId');
                        return false;
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert('操作失败！！！' + XMLHttpRequest.status + "|" + XMLHttpRequest.readyState + "|" + textStatus, {icon: 5});
                }
            });
        });
    });
</script>
</body>
</html>
